﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class StatementsElement : SyntaxTreeElement
    {
        private LabelElement label;
        private List<StatementElement> statements;

        public LabelElement Label { get { return label; } set { label = value; } }
        public List<StatementElement> Statements { get { return statements; } set { statements = value; } }

        public StatementsElement(TokenInfo StartInfo, LabelElement Label, List<StatementElement> Statements, List<TokenInfo> Comments)
            : base(StartInfo, Comments)
        {
            label = Label;
            statements = Statements;
        }

        public override string ToString()
        {
            string result = (label != null) ? string.Format("{0}\r\n", label) : string.Empty;
            if (statements != null)
                result += string.Format("{0};\r\n", statements.Join(";\r\n"));
            return result;
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (label != null)
                yield return label;
            if (statements != null)
                foreach (StatementElement statement in statements)
                    yield return statement;
        }
    }
}
